/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Visual;

import Logica.Especialidad;
import Logica.Localidad;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JDesktopPane;
import javax.swing.JList;

/**
 *
 * @author Pablo
 */
public class Localidades extends javax.swing.JInternalFrame {
    JDesktopPane miEscritorio;
    ControladoraVisual miVisual;
    DefaultListModel modeloZonas = new DefaultListModel();
    DefaultListModel modeloExistentes = new DefaultListModel();
    DefaultListModel modeloSeleccionadas = new DefaultListModel();
    JList listZonas = new JList();
    DefaultComboBoxModel modeloLocalidadesTaller = new DefaultComboBoxModel();
    
    /**
     * Creates new form Localidades
     */
    public Localidades(JDesktopPane miEscritorio, ControladoraVisual miVisual, DefaultListModel modeloZonas, JList listZonas,
            DefaultComboBoxModel modeloLocalidadesTaller) {
        initComponents();
        setTitle("Localidades");
        this.modeloZonas = modeloZonas;
        this.miVisual = miVisual;
        this.miEscritorio = miEscritorio;
        this.listExistentes.setModel(modeloExistentes);
        this.listSeleccionadas.setModel(modeloSeleccionadas);
        
        this.listZonas = listZonas;
        this.cargarExistentes();
        
    }
    
     public void cargarExistentes(){
        List<Localidad> localidades = miVisual.dameLocalidades();
        for(Localidad miLocalidad:localidades){
            this.modeloExistentes.addElement(miLocalidad);
        }
    }
    public void cargarSeleccionadas(){
      
        this.modeloSeleccionadas.addElement(listExistentes.getSelectedValue());
        this.modeloExistentes.removeElement(listExistentes.getSelectedValue());
        
    }
    public void quitarSeleccionadas(){
        this.modeloExistentes.addElement(listSeleccionadas.getSelectedValue());
        this.modeloSeleccionadas.removeElement(listSeleccionadas.getSelectedValue());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        listSeleccionadas = new javax.swing.JList();
        btnAgregarSeleccionadas = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        listExistentes = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        btnQuitar = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        btnAgregar = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        btnNuevaLocalidad = new javax.swing.JButton();

        listSeleccionadas.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { " ", " " };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(listSeleccionadas);

        btnAgregarSeleccionadas.setText("Agregar Zonas Seleccionadas");
        btnAgregarSeleccionadas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarSeleccionadasActionPerformed(evt);
            }
        });

        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        listExistentes.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { " ", " " };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane2.setViewportView(listExistentes);

        jLabel1.setText("Localidades Existentes");

        btnQuitar.setText("<< Quitar");
        btnQuitar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnQuitarActionPerformed(evt);
            }
        });

        jLabel2.setText("Localidades Seleccionadas");

        btnAgregar.setText("Agregar >>");
        btnAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarActionPerformed(evt);
            }
        });

        btnNuevaLocalidad.setText("Nueva Localidad");
        btnNuevaLocalidad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNuevaLocalidadActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel1)
                                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(btnAgregar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(btnQuitar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel2)))
                            .addComponent(btnNuevaLocalidad))
                        .addGap(0, 18, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnAgregarSeleccionadas)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnCancelar)
                        .addGap(20, 20, 20)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane1)
                            .addComponent(jScrollPane2)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnQuitar)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnNuevaLocalidad)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAgregarSeleccionadas)
                    .addComponent(btnCancelar))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarActionPerformed
        this.cargarSeleccionadas();
    }//GEN-LAST:event_btnAgregarActionPerformed

    private void btnQuitarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnQuitarActionPerformed
        this.quitarSeleccionadas();
    }//GEN-LAST:event_btnQuitarActionPerformed

    private void btnAgregarSeleccionadasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarSeleccionadasActionPerformed
         this.listZonas.setModel(this.modeloSeleccionadas);
         this.dispose();
    }//GEN-LAST:event_btnAgregarSeleccionadasActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnNuevaLocalidadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNuevaLocalidadActionPerformed
        frmAltaLocalidad unaLocalidad = new frmAltaLocalidad(miVisual,modeloExistentes,modeloLocalidadesTaller);
        miEscritorio.add(unaLocalidad);
        unaLocalidad.setMaximizable(true);
        unaLocalidad.setClosable(true);
        unaLocalidad.setVisible(true);
    }//GEN-LAST:event_btnNuevaLocalidadActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAgregar;
    private javax.swing.JButton btnAgregarSeleccionadas;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnNuevaLocalidad;
    private javax.swing.JButton btnQuitar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JList listExistentes;
    private javax.swing.JList listSeleccionadas;
    // End of variables declaration//GEN-END:variables
}
